package com.open.api.wechat.event;

import com.open.api.wechat.event.content.*;
import com.open.api.wechat.event.common.MsgContent;
import com.open.api.wechat.event.enums.PubMsgType;
import com.open.api.wechat.utils.XmlUtil;

/**
 * @author : zhaoxuan
 * @date : 2021/7/6 17:15
 * @description : ReceiveMsgService
 * @version: 1.0
 */
public interface MsgReceiveService {

    default void receiveMsg(String msgXml){
        MsgContent content = XmlUtil.xmlToBean(msgXml, MsgContent.class);
        PubMsgType msgType = PubMsgType.getByName(content.getMsgType());
        switch (msgType) {
            case TEXT:
                MsgTextContent textContent = XmlUtil.xmlToBean(msgXml, MsgTextContent.class);
                afterTextMsg(textContent);
                break;
            case IMAGE:
                MsgImageContent imageContent = XmlUtil.xmlToBean(msgXml, MsgImageContent.class);
                afterImageMsg(imageContent);
                break;
            case VOICE:
                MsgVoiceContent voiceContent = XmlUtil.xmlToBean(msgXml, MsgVoiceContent.class);
                afterVoiceMsg(voiceContent);
                break;
            case VIDEO:
                MsgVideoContent videoContent = XmlUtil.xmlToBean(msgXml, MsgVideoContent.class);
                afterVideoMsg(videoContent);
                break;
            case SHORT_VIDEO:
                MsgVideoContent shortVideoContent = XmlUtil.xmlToBean(msgXml, MsgVideoContent.class);
                afterShortVideoMsg(shortVideoContent);
                break;
            case LINK:
                MsgLinkContent linkContent = XmlUtil.xmlToBean(msgXml, MsgLinkContent.class);
                afterLinkMsg(linkContent);
                break;
            case LOCATION:
                MsgLocationContent locationContent = XmlUtil.xmlToBean(msgXml, MsgLocationContent.class);
                afterLocationMsg(locationContent);
                break;
            default:
                break;
        }
    }

    default void afterTextMsg(MsgTextContent content){
        return;
    }

    default void afterImageMsg(MsgImageContent content){
        return;
    }

    default void afterVoiceMsg(MsgVoiceContent content){
        return;
    }

    default void afterVideoMsg(MsgVideoContent content){
        return;
    }

    default void afterShortVideoMsg(MsgVideoContent content){
        return;
    }

    default void afterLocationMsg(MsgLocationContent content){
        return;
    }

    default void afterLinkMsg(MsgLinkContent content){
        return;
    }
}
